package chapterSystem.client.model.enums;

/**
 * User: Svetlana Zemlyanskaya(svetazem@yandex-team.ru)
 * Date: 4/8/12
 */
public enum UnitType {
    COMMON(1, "Common"),
    ADDITIONAL(2, "Additional");

    private final int id;
    private final String name;

    UnitType(final int id, final String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public static UnitType byCode(final int code) {
        for (final UnitType type : UnitType.values()) {
            if (type.id == code) {
                return type;
            }
        }
        return UnitType.COMMON;
    }

    @Override
    public String toString() {
        return name;
    }
}
